// pages/private/nickname.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    publicUrl: app.globalData.publicUrl,
    toast1Hidden: true,
    modalHidden: true,
    modalHidden2: true,
    notice_str: '',
    field:'',
    id:'',
    nickname:'请输入昵称',
    inputname:'',
    mb:'请输入手机号码'
  },
  toast1Change: function (e) {
    this.setData({ toast1Hidden: true });
  },
  //弹出确认框  
  modalTap: function (e) {
    this.setData({
      modalHidden: false
    })
  },
  confirm_one: function (e) {
    console.log(e);
    this.setData({
      modalHidden: true,
      toast1Hidden: false,
      notice_str: '修改成功'
    });
  },
  cancel_one: function (e) {
    console.log(e);
    this.setData({
      modalHidden: true,
      toast1Hidden: false,
      notice_str: '取消成功'
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onLoad:function(options){
      console.log(options.id)
      console.log(options.field)
      this.setData({
        field: options.field,
        id:options.id
      })
  },
  onShow: function () {
    /* var that = this;
    wx.request({
      url: 'https://baidu.com',
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        that.setData({
          nickname: '驴小毛'
        })
      },
    }) */
  },
  inputnickname:function(e){
  //  console.log(e.detail.value)
    this.setData({
      inputname: e.detail.value,
      id: e.currentTarget.dataset.id,
      field: e.currentTarget.dataset.field
    })
  },
  inputmobile:function(e){
  //  console.log(e.detail.value)
    this.setData({
      inputname:e.detail.value
    })
  },
  //修改昵称
  formSubmit: function (e) {
    var that = this;
    var name = that.data.inputname;
    // console.log(name)
    wx.request({
      url: that.data.publicUrl + 'user_nickname',
      method:'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data:{
        id: wx.getStorageSync('uid'),
        nickname: name,
      },

      success: function(res){
        
        if (res.data.message=="OK"){
          // console.log("成功");
             //跳转路径
          wx.reLaunch({
            url: '/pages/private/private?id=' + wx.getStorageSync('uid')
          })
        }    
      },
    })
 
  },

})